<template>
  <div class="tool-bar">
    <div class="tool-bar-item" v-for="(item,index) in toolBarData" :key='index' @click="onChangeFragment(item,index)">
      <img class="tool-bar-item-img" :src="[selectItemIndex===index?item.hIcon:item.nIcon]" />
      <p class="tool-bar-item-name" :class="{'tool-bar-item-name-h':index===selectItemIndex}">{{item.name}}</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'tool-bar',
  components: {

  },
  data () {
    return {
      selectItemIndex: 0,
      toolBarData: [{
        nIcon: require('@img/home-n.svg'),
        hIcon: require('@img/home-h.svg'),
        name: '首页',
        componentName: 'home'
      },
      {
        nIcon: require('@img/shopping-n.svg'),
        hIcon: require('@img/shopping-h.svg'),
        name: '购物车',
        componentName: 'shopping'
      },
      {
        nIcon: require('@img/my-n.svg'),
        hIcon: require('@img/my-h.svg'),
        name: '我的',
        componentName: 'my'
      }
      ]
    }
  },
  mounted () {

  },
  methods: {
    onChangeFragment (item, index) {
      this.selectItemIndex = index
      this.$emit('onChangeFragment', item.componentName)
    }
  }
}
</script>

<style lang="scss" scoped>
  @import '@css/style.scss';

  .tool-bar {
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid $lineColor;
    box-shadow: 0px 0 16px 0 rgba(0, 0, 0, 0.2);

    &-item {
      display: flex;
      flex-direction: column;
      flex-wrap: nowrap;
      justify-content: space-around;
      align-items: center;
      text-align: center;
      padding: px2rem(4) px2rem(12);

      &-img {
        width: px2rem(22);
        height: px2rem(22);
      }

      &-name {
        font-size: px2rem(14);
        margin-top: px2rem(4);

        &-h {
          color: $mainColor;
        }
      }

    }
  }
</style>
